/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgSkillLevel
    {
        private readonly Dictionary<int, CfgSkillLevel> _dataMap;
        private readonly List<CfgSkillLevel> _dataList;

        /// <summary>
        /// SkillID 和 SkillLevel 联合索引map(key1:SkillID, Key2:SkillLevel, value:Id)
        /// </summary>
        public IReadOnlyDictionary<int, IReadOnlyDictionary<int, int>> skillIdLvMap { get; private set; }

        public TbCfgSkillLevel(ByteBuf _buf)
        {
            //first read common data
            _TbCommonSkillLevel _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonSkillLevel(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgSkillLevel>(size * 3 / 2);
            _dataList = new List<CfgSkillLevel>(size);

            for (int i = 0; i < size; i++)
            {
                CfgSkillLevel _v;
                _v = CfgSkillLevel.DeserializeCfgSkillLevel(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, IReadOnlyDictionary<int, int>> (__n0 * 3 / 2); skillIdLvMap = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { int __k0; __k0 = _buf.ReadInt(); IReadOnlyDictionary<int, int> __v0; { int __n1 = _buf.ReadSize(); var __f1 = new Dictionary<int, int> (__n1 * 3 / 2); __v0 = __f1 ; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ) { int __k1; __k1 = _buf.ReadInt(); int __v1; __v1 = _buf.ReadInt(); __f1.Add(__k1, __v1); } } __f0.Add(__k0, __v0); } }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgSkillLevel> DataMap => _dataMap;
        public IReadOnlyList<CfgSkillLevel> DataList => _dataList;

        public CfgSkillLevel Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgSkillLevel] config not found,id:" + key.ToString());

            return null;
        }

        public CfgSkillLevel GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "skilllevel";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgSkillLevel LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgSkillLevel(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgSkillLevel
    {
        private CfgSkillLevel(ByteBuf _buf, _TbCommonSkillLevel _commonData)
        {
            Id = _buf.ReadInt();
            SkillID = _buf.ReadInt();
            SkillLevel = _buf.ReadInt();
            UpNeedHeroLv = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Cost = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; GoldCost = _commonData._field1[dataIndex]; }
            IsShow = _buf.ReadBool();
            EffectText = TableCenter.GetI18NText(_buf.ReadInt());

            PostInit();
        }

        internal static CfgSkillLevel DeserializeCfgSkillLevel(ByteBuf _buf, _TbCommonSkillLevel _commonData)
        {
            return new CfgSkillLevel(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 英雄技能ID
        /// </summary>
        public int SkillID { get; private set; }
        /// <summary>
        /// 英雄技能等级（1为初始等级）
        /// </summary>
        public int SkillLevel { get; private set; }
        /// <summary>
        /// 升到下一级所需英雄等级
        /// </summary>
        public int UpNeedHeroLv { get; private set; }
        /// <summary>
        /// 升级所需非金币消耗
        /// </summary>
        public IReadOnlyList<int> Cost { get; private set; }
        /// <summary>
        /// 升级所需金币消耗
        /// </summary>
        public IReadOnlyList<int> GoldCost { get; private set; }
        /// <summary>
        /// 是否在总览弹窗中显示（为true时显示）
        /// </summary>
        public bool IsShow { get; private set; }
        /// <summary>
        /// 当前等级技能完整描述
        /// </summary>
        public string EffectText { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonSkillLevel
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal _TbCommonSkillLevel(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
